package cn.funeralobjects.upms.enums;

import cn.funeralobjects.cache.EnumCache;
import cn.funeralobjects.model.EnumCodePair;
import cn.funeralobjects.util.EnumUtils;
import lombok.Getter;

/**
 * 用户凭证类型
 *
 * @author FuneralObjects
 * Create date: 2020/6/3 2:16 PM
 */
public enum UserCertificateType implements EnumCodePair<UserCertificateType> {
    /**
     * 电话号码
     */
    TEL("tel"),
    /**
     * 电子有限
     */
    EMAIL("email"),
    /**
     * 用户名
     */
    USERNAME("username");

    @Getter
    private final String code;

    UserCertificateType(String code) {
        this.code = code;
    }

    private static boolean isCached = false;

    @Override
    public UserCertificateType getContent() {
        return this;
    }

    public static UserCertificateType of(String code) {
        if (!isCached) {
            if (!EnumCache.isRegistered(UserCertificateType.class)) {
                EnumCache.registerCache(UserCertificateType.class, e -> e.code);
            }
            isCached = true;
        }

        return EnumUtils.of(code, UserCertificateType.class);
    }
}
